/*
 * Copyright (C) 2013 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using UnityEngine;
using System.Collections;

public class Utils {
    public static Vector3 VectorFromAziElev(float azi, float elev, float magnitude) {
        azi = azi * Mathf.PI * 2 / 360.0f;
        elev = elev * Mathf.PI * 2 / 360.0f;
        return magnitude * new Vector3(
            Mathf.Sin(azi) * Mathf.Cos(elev),
            Mathf.Sin(elev),
            Mathf.Cos(azi) * Mathf.Cos(elev));
    }

    public static string IntWithLeadingZeroes(int places, int i) {
        string s = "" + i;
        while (s.Length < places) s = "0" + s;
        return s;
    }

    public static void EnableRenderers(GameObject o, bool enable) {
        if (o.renderer != null) o.renderer.enabled = enable;
        foreach (Renderer r in o.GetComponentsInChildren<Renderer>()) {
            if (r != null) r.enabled = enable;
        }
    }
}
